package com.wdg.controller;

import com.wdg.util.FileUploadUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/hf_uplaod")
public class UpLoadFileController {

    /**/
    @RequestMapping("/uploadImage")
    @CrossOrigin(origins = "*")
    public String uploadImage(MultipartFile file,HttpServletResponse response){
//        初始化
        FileUploadUtil fileUpload = new FileUploadUtil();

        String fileKey = fileUpload.uploadImg2Oss(file);

//
//        response.setHeader("Access-Control-Allow-Origin", "*");
//        response.setHeader("Cache-Control","no-cache");

        return fileUpload.getUrl("foodupload/" + fileKey);
    }

}
